<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>更新用户信息</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
    <!--<link rel="stylesheet" type="text/css" href="CSS/bootstrap-switch.min.css" />-->
    <!--<link rel="stylesheet" type="text/css" href="CSS/addContract.css" />-->


    <script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
    <script type="text/javascript" src="js/ajax.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/mui.min.js"></script>
    <script type="text/javascript" >
        var   n=self.location.href.indexOf("?uid")//查看是否包含参数
        var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
        if(n>0)//存在参数
        {
            var   uid=self.location.href.substr(n+5);
            mui.ready(function() {
                mui.ajax(hosturl+"/user/byUserId", {
                    data: {
                        id: uid
                    },
                    dataType: "json",
                    type: "post",
                    timeout: 10000,
                    success: function(data) {
                        if(data.status=="ok"){
                            $("#userName").val(data.body.userName);
                            $("#name").val(data.body.name);
                            $("#department").val(data.body.department);
                            $("#OA").val(data.body.oa);
                            $("#emailAddress").val(data.body.emailAddress);
                            $("#phone").val(data.body.phone);
                            $("#primarysalt").val(data.body.primarySalt);
                        }


                    },
                    error: function(xhr, type, errorThrown) {
                        console.log(type);
                    }
                });
            });
        }
    </script>

</head>

<body>

<div class="addMain" style="margin:0px auto;width:266px;height:200px;">
    <div >


        用户编号：<input disabled="disabled" type="text" id="userName" class="add-text" />
    </div>
    <div >

        用户名称：<input disabled="disabled" type="text" id="name" class="add-text" />
    </div>
    <div >


        用户部门：<input type="text" id="department" />
    </div>
    <div>


        OA邮箱：<input type="text" id="OA"/>
    </div>
    <div>
        普通邮箱：<input type="text" id="emailAddress" class="add-text" />
    </div>
    <div>

        用户手机：<input id="phone"  type="text"/>
    </div>
    <!--<div >-->


        <!--primarySalt：<input type="text" id="primarysalt" />-->
    <!--</div>-->
    <div class="">
        <input type="button" id="btn" class="add-receive"
               style="height:23px;width:84px;line-height:20px;font-size:12px;" value="保存"/>
     
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    window.onload=function(){

        var btnUpdateUser = document.getElementById("btn");
        btnUpdateUser.addEventListener("click",function(){
                    var userName = document.getElementById('userName').value;
                    var name = document.getElementById('name').value;
                    var department = document.getElementById('department').value;
                    var OA = document.getElementById('OA').value;
                    var emailAddress = document.getElementById('emailAddress').value;
                    var phone = document.getElementById('phone').value;
//                    var primarysalt = document.getElementById('primarysalt').value;
                    if(userName == ""){
                        layer.msg('用户编号不能为空！', function(){});
                        return;
                    }
                    if(name == ""){
                        layer.msg('用户名称不能为空！', function(){});
                        return;
                    }
                    if(department == ""){
                        layer.msg('用户部门不能为空！', function(){});
                        return;
                    }
                    if(OA == "" && emailAddress==""){
                        layer.msg('OA邮箱和普通邮箱不能全部为空！', function(){});
                        return;
                    }

                    mui.ajax(hosturl+"/user/updateUserByAdmin", {
                        data: {
                            "id":uid,
                            "userName": userName,
                            "name": name,
                            "department": department,
                            "oa": OA,
                            "emailAddress": emailAddress,
                            "phone": phone,
//                            "primarySalt":primarysalt
                        },
                        dataType: "json",
                        type: "post",
                        timeout: 10000,
                        success: function(data) {
                            var index = parent.layer.getFrameIndex(window.name);
                            if(data.status == "ok"){
                                parent.$("#handle_status").val('OK');
                                parent.layer.close(index);
                            }else if(data.status == "error"){
                                layer.msg(data.description, function(){
                                });
                            }

                        },
                        error: function(xhr, type, errorThrown) {
                            console.log(type);
                        }
                    });

                }
        );
    }
</script>

</body>
</html>